<?php

// get modul boxed
function get_modulboxed($position, $name='') {
    global $MySQL_DB;

    // if name passed? then only output this boxed modul
    if($name != '') {
        $res_moduleboxed = execute_query("SELECT ID AS 'modulID' FROM %PRE%module WHERE name = '".$name."' and activeted = 1 and boxed = 1",$MySQL_DB);
        if($moduleboxed = $res_moduleboxed->fetch_object()) {
            $modul = new Modul($moduleboxed->modulID);
            $modul->displayModul();
        }
    }
    // get all boxed module at passed position
    else {
        $res_moduleboxed = execute_query("SELECT ID AS 'modulID' FROM %PRE%module WHERE position = '".$position."' and activeted = 1 and boxed = 1 ORDER BY sort",$MySQL_DB);
        while($moduleboxed = $res_moduleboxed->fetch_object()) {
            $modul = new Modul($moduleboxed->modulID);
            $modul->displayModul();
        }
    }
}

// get modul boxed
function get_modul() {
    global $MySQL_DB;
    global $indexModul;

    // site var set?
    if(isset($_GET['site'])) {
        // check for valid site
        if(!preg_match('/[^0-9-._a-z]/i', $_GET['site'])) {
            $site = $_GET['site'];
            $res_module = execute_query("SELECT %PRE%module.ID AS 'modulID', %PRE%sites.parameter AS 'parameter' FROM %PRE%module INNER JOIN %PRE%sites ON %PRE%sites.module_ID = %PRE%module.ID WHERE %PRE%module.activeted = 1 and %PRE%sites.name = '".$site."'",$MySQL_DB);
            if($module = $res_module->fetch_object()) {
                $modul = new Modul($module->modulID);
                $modul->setSiteParameter($module->parameter);
                $modul->displayModul();
            }
            // modul not activated or available
            else {
                // output modul not available
                $template_vars = array(
                    "message" => $indexModul->getText('modul_not_available')
                );
                echo $indexModul->getTemplate('warning_content',$template_vars);
            }
        }
        else {
            header("location: index.php");
        }
    }
    else {
        // get default page
        $res_module = execute_query("SELECT %PRE%module.ID AS 'modulID' FROM %PRE%settings INNER JOIN %PRE%sites ON %PRE%sites.name = %PRE%settings.defaultsite INNER JOIN %PRE%module ON %PRE%sites.module_ID = %PRE%module.ID WHERE %PRE%module.activeted = 1 and %PRE%module.boxed = 0",$MySQL_DB);
        if($module = $res_module->fetch_object()) {
            $modul = new Modul($module->modulID);
            $modul->displayModul();
        }
        // no default site? write error log
        else {
            write_errorlog('Failed to load default site!',3,'modulfunc.inc.php');
        }
    }

}

?>